﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System.Collections.Generic;

using PdfCreative.Pdf.Graphics.PathElements;

namespace PdfCreative.Pdf.Graphics
{
    /// <summary>
    /// The GraphicsPath class encapsulates a number of graphics elements, such as lines, curves and arcs, that make up a shape that can
    /// be drawn, filled or used as a clipping path.
    /// </summary>
    public class GraphicsPath
    {
        // Private fields
        // ==============
        #region Private fields
        private List<PathElement> _elements;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves the elements of this path.
        /// </summary>
        internal IEnumerable<PathElement> Elements
        {
            get { return _elements;  }
        }
        #endregion



        // Public methods
        // ==============
        #region Public methods
        /// <summary>
        /// Extends the path by adding a bezier curve using the specified coordinates and control points.
        /// </summary>
        /// <param name="x1">The x coordinate of the curve's starting point</param>
        /// <param name="y1">The y coordinate of the curve's starting point</param>
        /// <param name="x1c">The x coordinate of the curve's first control point</param>
        /// <param name="y1c">The y coordinate of the curve's first control point</param>
        /// <param name="x2c">The x coordinate of the curve's second control point</param>
        /// <param name="y2c">The y coordinate of the curve's second control point</param>
        /// <param name="x2">The x coordinate of the curve's end point</param>
        /// <param name="y2">The y coordinate of the curve's end point</param>
        public void AddCurve(float x1, float y1, float x1c, float y1c, float x2c, float y2c, float x2, float y2)
        {
            _elements.Add(new BezierElement(x1, y1, x1c, y1c, x2c, y2c, x2, y2));
        }

        /// <summary>
        /// Adds a rectangle to the path.
        /// </summary>
        /// <param name="rectangle">The rectangle to add</param>
        public void AddRectangle(Rectangle rectangle)
        {
            _elements.Add(new RectangleElement(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height));
        }

        /// <summary>
        /// Adds a rounded rectangle to the path.
        /// </summary>
        /// <param name="rectangle">The bounding box of the rounded rectangle</param>
        /// <param name="radius">The size of the rounded corners of the rectangle.</param>
        public void AddRoundedRectangle(Rectangle rectangle, float radius)
        {
            _elements.Add(new RoundedRectangleElement(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, radius));
        }

        /// <summary>
        /// Adds a line to the path object.
        /// </summary>
        /// <param name="x1">The line start point's x coordinate</param>
        /// <param name="y1">The line start point's y coordinate</param>
        /// <param name="x2">The line end point's x coordinate</param>
        /// <param name="y2">The line end point's y coordinate</param>
        public void AddLine(float x1, float y1, float x2, float y2)
        {
            _elements.Add(new LineElement(x1, y1, x2, y2));
        }

        /// <summary>
        /// Closes the current shape. Subsequent additions will be considered part of another shape.
        /// </summary>
        public void Close()
        {
            _elements.Add(new CloseElement());
        }
        #endregion



        // Public constructor
        // ==================
        #region Public constructor
        /// <summary>
        /// Constructs a new GraphicsPath instance.
        /// </summary>
        public GraphicsPath()
        {
            _elements = new List<PathElement>();
        }
        #endregion

    } // GraphicsPath class
}
